package com.itheima.service.impl;


import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;


@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;


    @Override
    public List<Dept> list() {
        return deptMapper.findAll();
    }
    @Override
    public void delete(Integer id) {
        //Integer deleted = deptMapper.delete(id);
        //System.out.println("删除数据的结果为: " + deleted);
        deptMapper.deleteById(id);//重新定义的一个方法根据id删除部门
    }



    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.add(dept);
    }



    @Override
    public Dept getById(Integer id) {
        return deptMapper.getById(id);
    }

    @Override
    public
    void update(Dept dept) {
        //1.补全基础属性
        dept.setUpdateTime(LocalDateTime.now());
        //2.更新数据
        deptMapper.update(dept);
    }
}
